package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.RecDispatchCarEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 车辆调度表Provider
 *
 * @author generator
 * @date 2020-07-06 17:23
 */
public class RecDispatchCarProvider {

    /**
     * 增加RecDispatchCar
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-07-06 17:23
     */
    public String insertRecDispatchCar(@Param("entity") RecDispatchCarEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" rec_dispatch_car ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" rec_id ", " #{entity.recId,jdbcType=INTEGER} ");
                VALUES(" rec_car_id ", " #{entity.recCarId,jdbcType=INTEGER} ");
                VALUES(" rec_car_no ", " #{entity.recCarNo,jdbcType=VARCHAR} ");
                VALUES(" dispatch_user_name ", " #{entity.dispatchUserName,jdbcType=VARCHAR} ");
                VALUES(" dispatch_user_id ", " #{entity.dispatchUserId,jdbcType=INTEGER} ");
                VALUES(" dispatch_out_time ", " #{entity.dispatchOutTime,jdbcType=TIMESTAMP} ");
                VALUES(" dispatch_back_time ", " #{entity.dispatchBackTime,jdbcType=TIMESTAMP} ");

                if (entity.getDispatchTime() != null) {
                    VALUES(" dispatch_time ", " #{entity.dispatchTime,jdbcType=TIMESTAMP} ");
                }

                VALUES(" odometer ", " #{entity.odometer,jdbcType=DECIMAL} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改RecDispatchCar
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-07-06 17:23
     */
    public String updateRecDispatchCar(@Param("entity") RecDispatchCarEntity entity) {
        return new SQL() {
            {
                UPDATE(" rec_dispatch_car ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" rec_id = #{entity.recId,jdbcType=INTEGER} ");
                SET(" rec_car_id = #{entity.recCarId,jdbcType=INTEGER} ");
                SET(" rec_car_no = #{entity.recCarNo,jdbcType=VARCHAR} ");
                SET(" dispatch_user_name = #{entity.dispatchUserName,jdbcType=VARCHAR} ");
                SET(" dispatch_user_id = #{entity.dispatchUserId,jdbcType=INTEGER} ");
                SET(" dispatch_out_time = #{entity.dispatchOutTime,jdbcType=TIMESTAMP} ");
                SET(" dispatch_back_time = #{entity.dispatchBackTime,jdbcType=TIMESTAMP} ");

                if (entity.getDispatchTime() != null) {
                    SET(" dispatch_time = #{entity.dispatchTime,jdbcType=TIMESTAMP} ");
                }

                SET(" odometer = #{entity.odometer,jdbcType=DECIMAL} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询RecDispatchCar列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-07-06 17:23
     */
    public String listRecDispatchCar(@Param("entity") RecDispatchCarEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,rec_id,rec_car_id,rec_car_no,dispatch_user_name,dispatch_user_id,dispatch_out_time,dispatch_back_time,dispatch_time,odometer,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" rec_dispatch_car ");

                if (entity.getRecId() != null) {
                    WHERE(" rec_id = #{entity.recId,jdbcType=INTEGER} ");
                }

                if (entity.getRecCarId() != null) {
                    WHERE(" rec_car_id = #{entity.recCarId,jdbcType=INTEGER} ");
                }

                if (entity.getRecCarNo() != null) {
                    WHERE(" rec_car_no = #{entity.recCarNo,jdbcType=VARCHAR} ");
                }

                if (entity.getDispatchUserName() != null) {
                    WHERE(" dispatch_user_name = #{entity.dispatchUserName,jdbcType=VARCHAR} ");
                }

                if (entity.getDispatchUserId() != null) {
                    WHERE(" dispatch_user_id = #{entity.dispatchUserId,jdbcType=INTEGER} ");
                }

                if (entity.getDispatchOutTime() != null) {
                    WHERE(" dispatch_out_time = #{entity.dispatchOutTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getDispatchBackTime() != null) {
                    WHERE(" dispatch_back_time = #{entity.dispatchBackTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getDispatchTime() != null) {
                    WHERE(" dispatch_time = #{entity.dispatchTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getOdometer() != null) {
                    WHERE(" odometer = #{entity.odometer,jdbcType=DECIMAL} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}